﻿using Microsoft.UI.Xaml.Controls;
using Windows.Foundation;
using WinTime.Helpers;
using WinTime.ViewModels;

namespace WinTime.Views;

public sealed partial class MainPage : Page
{
    public MainViewModel ViewModel
    {
        get;
    }

    public MainPage()
    {
        ViewModel = App.GetService<MainViewModel>();
        InitializeComponent();
        AppList.ItemsSource = ViewModel.AppList;
        WebViewCharts.Source = new Uri(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets\\Views\\echarts.html"));
        WebViewCharts.NavigationCompleted += WebViewCharts_NavigationCompleted;
    }

    private void WebViewCharts_NavigationCompleted(WebView2 sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs args)
    {
        LoadRadarChart();
    }

    private async void LoadRadarChart()
    {
        var echartsJs = EchartsHelper.RadarChart("", "{data: ['今日'],show:false}", "[{value: [42, 3, 5, 20, 88, 75],name: '今日',areaStyle:{color:'#4a4b9d'}}]");
        await WebViewCharts.ExecuteScriptAsync(echartsJs);
    }

    protected override Size MeasureOverride(Size availableSize)
    {
        var activeHight = availableSize.Height - 80;
        AppList.Height = activeHight;
        WebViewCharts.Height = activeHight;
        return base.MeasureOverride(availableSize);
    }
}
